﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using GameStudio.IDE.Common.Events;
using Microsoft.Windows.Controls.Ribbon;
using GameStudio.Common;
using Microsoft.Practices.ServiceLocation;
using Utils.EventAggregator;
using GameStudio.IDE.Common;

namespace GameStudio.IDE.Controls
{
    [TemplatePart(Name = "uxRibbon", Type = typeof(Ribbon))]
    [TemplatePart(Name = "btnEmptyProject", Type = typeof(RibbonButton))]
    [TemplatePart(Name = "btnClassLibraryProject", Type = typeof(RibbonButton))]
    [TemplatePart(Name = "btnOpenProject", Type = typeof(RibbonButton))]
    [TemplatePart(Name = "btnAddNewItem", Type = typeof(RibbonButton))]
    [TemplatePart(Name="newProjectMenuItem",Type=typeof(RibbonApplicationMenuItem))]
    [TemplatePart(Name = "openProjectMenuItem", Type = typeof(RibbonApplicationMenuItem))]
    [TemplatePart(Name = "saveProjectMenuItem", Type = typeof(RibbonApplicationMenuItem))]
    [TemplatePart(Name = "saveAsMenuItem", Type = typeof(RibbonApplicationMenuItem))]
    [TemplatePart(Name = "closeProjectMenuItem", Type = typeof(RibbonApplicationMenuItem))]
    [TemplatePart(Name = "exitMenuItem", Type = typeof(RibbonApplicationMenuItem))]
    public class RibbonContainer :Control
    {
        RibbonButton btnEmptyProject;
        RibbonButton btnClassLibraryProject;
        RibbonButton btnSaveProject;
        RibbonButton btnSaveAs;
        RibbonButton btnCloseProject;
        RibbonButton btnOpenProject;
        RibbonButton btnAddNewItem;
        RibbonButton btnOpenItem;
        RibbonApplicationMenuItem newProjectMenuItem;
        RibbonApplicationMenuItem openProjectMenuItem;
        RibbonApplicationMenuItem saveProjectMenuItem;
        RibbonApplicationMenuItem saveAsMenuItem;
        RibbonApplicationMenuItem closeProjectMenuItem;
        RibbonApplicationMenuItem exitMenuItem;

        //public ProjectFactory CurProjectFactory;

        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();
            btnEmptyProject = (RibbonButton)GetTemplateChild("btnEmptyProject");
            btnEmptyProject.Click += new RoutedEventHandler(btnEmptyProject_Click);

            btnClassLibraryProject = (RibbonButton)GetTemplateChild("btnClassLibraryProject");
            btnClassLibraryProject.Click += new RoutedEventHandler(btnClassLibraryProject_Click);

            btnSaveProject = (RibbonButton)GetTemplateChild("btnSaveProject");
            btnSaveProject.Click += new RoutedEventHandler(btnSaveProject_Click);

            btnSaveAs = (RibbonButton)GetTemplateChild("btnSaveAs");
            btnSaveAs.Click += new RoutedEventHandler(btnSaveAs_Click);

            btnCloseProject = (RibbonButton)GetTemplateChild("btnCloseProject");
            btnCloseProject.Click += new RoutedEventHandler(btnCloseProject_Click);

            btnOpenProject = (RibbonButton)GetTemplateChild("btnOpenProject");
            btnOpenProject.Click += new RoutedEventHandler(btnOpenProject_Click);

            btnAddNewItem = (RibbonButton)GetTemplateChild("btnAddNewItem");
            btnAddNewItem.Click += new RoutedEventHandler(btnAddNewItem_Click);

            //btnOpenItem = (RibbonButton)GetTemplateChild("btnOpenItem");
            //btnOpenItem.Click += new RoutedEventHandler(btnOpenItem_Click);

            newProjectMenuItem = (RibbonApplicationMenuItem)GetTemplateChild("newProjectMenuItem");
            newProjectMenuItem.Click+=new RoutedEventHandler(newProjectMenuItem_Click);

            openProjectMenuItem = (RibbonApplicationMenuItem)GetTemplateChild("openProjectMenuItem");
            openProjectMenuItem.Click+=new RoutedEventHandler(openProjectMenuItem_Click);

            saveProjectMenuItem = (RibbonApplicationMenuItem)GetTemplateChild("saveProjectMenuItem");
            saveProjectMenuItem.Click+=new RoutedEventHandler(saveProjectMenuItem_Click);

            saveAsMenuItem = (RibbonApplicationMenuItem)GetTemplateChild("saveAsMenuItem");
            saveAsMenuItem.Click+=new RoutedEventHandler(saveAsMenuItem_Click);

            closeProjectMenuItem = (RibbonApplicationMenuItem)GetTemplateChild("closeProjectMenuItem");
            closeProjectMenuItem.Click+=new RoutedEventHandler(closeProjectMenuItem_Click);

            exitMenuItem = (RibbonApplicationMenuItem)GetTemplateChild("exitMenuItem");
            exitMenuItem.Click+=new RoutedEventHandler(exitMenuItem_Click);
        }

        void btnCloseProject_Click(object sender, RoutedEventArgs e)
        {
            throw new NotImplementedException();
        }

        void btnEmptyProject_Click(object sender, RoutedEventArgs e)
        {
            wndNewProject newproject = new wndNewProject("emptyProject1","Empty Project");
            newproject.Show();
        }

        void btnClassLibraryProject_Click(object sender, RoutedEventArgs e)
        {
            wndNewProject newproject = new wndNewProject("classLibraryProject1", "Class Project");
            newproject.Show();
        }

        void btnSaveProject_Click(object sender, RoutedEventArgs e)
        {
            throw new NotImplementedException();
        }

        void btnSaveAs_Click(object sender, RoutedEventArgs e)
        {
            throw new NotImplementedException();
        }


        void btnOpenItem_Click(object sender, RoutedEventArgs e)
        {
            OpenItemControl openItem = new OpenItemControl();
        }

        void btnAddNewItem_Click(object sender, RoutedEventArgs e)
        {
            WndAddNewItem wnd = new WndAddNewItem();
            wnd.Show();
        }

        void btnNewProject_Click(object sender, RoutedEventArgs e)
        {
            //WndCreateNewProject wnd = new WndCreateNewProject();
            //ControlTemplate template = (ControlTemplate)FindResource("NewProjectControlTemplate");
            //wnd.Content = new NewProjectControl() { Template = template };
            wndNewProject wnd = new wndNewProject();
            wnd.Show();
        }

        void btnOpenProject_Click(object sender, RoutedEventArgs e)
        {
            OpenProjectcontrol OpenProject = new OpenProjectcontrol();
            //var eventAggregator = ServiceLocator.Current.GetInstance<IEventAggregator>();
            //   EventAgg.EventAggregator.GetEvent<NewProjectEvent>().Publish(CurProjectFactory);
        }

        void newProjectMenuItem_Click(object sender, RoutedEventArgs e)
        {
            wndNewProject wnd = new wndNewProject();
            wnd.Show();
        }

        void openProjectMenuItem_Click(object sender, RoutedEventArgs e)
        {
            OpenProjectcontrol OpenProject = new OpenProjectcontrol();
            //var eventAggregator = ServiceLocator.Current.GetInstance<IEventAggregator>();
            //   EventAgg.EventAggregator.GetEvent<NewProjectEvent>().Publish(CurProjectFactory);
        }

        void saveProjectMenuItem_Click(object sender, RoutedEventArgs e)
        {

        }

        void saveAsMenuItem_Click(object sender, RoutedEventArgs e)
        {

        }

        void closeProjectMenuItem_Click(object sender, RoutedEventArgs e)
        {

        }

        void exitMenuItem_Click(object sender, RoutedEventArgs e)
        {
           
        }
    }
}
